Enumerations
Pluto adds the following syntax:
plutoenum MyEnum beginOPTION_1,OPTION_2,OPTION_3endassert(OPTION_1 == 1)assert(OPTION_2 == 2)assert(OPTION_3 == 3)
Enums can start at a base number, and increment from there.
plutoenum MyEnum beginOPTION_1 = 0,OPTION_2,OPTION_3 = 5,OPTION_4endassert(OPTION_1 == 0)assert(OPTION_2 == 1)assert(OPTION_3 == 5)assert(OPTION_4 == 6)
Since this enum has a name, we can also access its enumerators with that:
plutoassert(MyEnum.OPTION_1 == 0)
Scoped Enums
You can force usage of the ENUM.ENUMERATOR syntax by using 'enum class':
plutoenum class MyEnum beginOPTION_1,OPTION_2,OPTION_3endassert(OPTION_1 == nil)assert(MyEnum.OPTION_1 == 1)
Reflection
When you have a named enum, not only can you get its enumerators, but also reflect upon it with some methods:
plutoenum MyEnum beginOPTION_1,OPTION_2,OPTION_3endfor k, v in MyEnum:kvmap() doprint(k, v) -- "OPTION_1 1" ...end
The following methods are available: :names(), :values(), :kvmap(), :vkmap()
Anonymous Enums
Enums can also be anonymous:
plutoenum beginOPTION_1,OPTION_2,OPTION_3endassert(OPTION_1 == 1)assert(OPTION_2 == 2)assert(OPTION_3 == 3)
Using Compatibility Mode?
You may need to use pluto_enum instead of enum. Alternatively, pluto_use enum will enable the keyword independently of environment settings.